# 定义商品信息的列表，每个元素是一个包含名称、数量、单价的元组
# 为了更精确，我们不再手动输入金额，而是通过计算得出
products = [
    ("金士顿U盘8G", 1, 40.00),
    ("胜创16GTF卡", 1, 50.00),
    ("读卡器", 1, 8.00),
    ("网线2米", 1, 5.00),
    ("三沙",1,20.00)
]

# 打印小票单号和时间
print("单号: DH202311010001")
print("时间: 2023-11-01 20:56:15")
print("\n名称\t\t数量\t单价\t金额")

# 初始化总价为0
total_amount_before_discount = 0

# 遍历商品列表，打印每个商品的信息，并计算总价
for product in products:
    name, quantity, unit_price = product
    amount = quantity * unit_price
    print(f"{name}\t{quantity}\t{unit_price:.2f}\t{amount:.2f}")
    total_amount_before_discount += amount

# 计算折扣和折后总价
discount_rate = 0.78
total_amount_after_discount = total_amount_before_discount * discount_rate

# 打印汇总信息
print("\n总数:", len(products))
print(f"原价总额: {total_amount_before_discount:.2f}")
print(f"折扣: {discount_rate * 100:.0f}%") # 将0.78转换为78%
print(f"折后总额: {total_amount_after_discount:.2f}")

# 假设实收金额等于折后总额
cash_received = total_amount_after_discount
change = cash_received - total_amount_after_discount

print(f"实收: {cash_received:.2f}")
print(f"找零: {change:.2f}")
print("收银: 管理员")